<template>
  <div>
      <el-row>
          <el-col :span="6">【题型】：{{translateQuestionType(list.questionType)}}</el-col>
          <el-col :span="6">【编号】：{{list.id}}</el-col>
          <el-col :span="6">【难度】：{{translateDifficulty(list.difficulty)}}</el-col>
          <el-col :span="6">【标签】：{{list.tags}}</el-col>
          <el-col :span="6">【学科】：{{list.subjectName}}</el-col>
          <el-col :span="6">【目录】：{{list.directoryName}}</el-col>
          <el-col :span="6">【方向】：{{list.direction}}</el-col>
      </el-row>
      <hr>
            <el-row>【题干】:</el-row>
            <el-row class="question" v-html="list.question"></el-row>
            <!-- 简答：只需要展示题干即可 -->
            <!-- 多选 -->
            <div v-if="list.questionType==2">
              <el-row>多选题 选项 :  (以下选中的选项为正确答案)</el-row>
              <el-row v-for="(item,index) in list.options" :key="index">
                  <el-checkbox :value="item.isRight?true:false">{{item.code}}.{{item.title}}</el-checkbox>
            </el-row>
            </div>
            <!-- 单选 -->
            <div v-if="list.questionType==1">
              <el-row>单选题 选项 :  (以下选中的选项为正确答案)</el-row>
              <el-row v-for="(item,index) in list.options" :key="index">
                  <el-radio :value="1" :label="item.isRight">{{item.code}}.{{item.title}}</el-radio>
              </el-row>
            </div>
        <hr>
        <el-row>
        【参考答案】: <el-button type="danger" @click="videoShow=true">视频答案预览</el-button>
        </el-row>
        <el-row v-if="videoShow">
            <video :src="list.videoURL" autoplay controls style="width:400px;height:300px"></video>
        </el-row>
        <hr>
        <el-row style="display:flex;align-items: center;">
            <span style="margin-right: 5px;">【答案解析】:</span>
            <span v-html="list.answer"></span>
        </el-row>
        <hr>
        <el-row>
            【题目备注】: {{list.remarks}}
        </el-row>
        <el-row type="flex" justify="end">
            <el-button type="primary" size="small" @click="$emit('close')">关闭</el-button>
        </el-row>
  </div>
</template>

<script>
// 获取基础题库详情
import { detail } from '@/api/hmmm/questions.js'
// 枚举文件 {难度, 题型}
import { difficulty, questionType } from '@/api/hmmm/constants.js'
export default {
  props: {
    subject: {
      type: Object,
      require: true
    }
  },
  data () {
    return {
      videoShow: false, // 视频解析 | 默认关闭
      list: {} // 数据列表
    }
  },
  created () {
    this.getList()
  },
  methods: {
    // 获取基础题库详情
    async getList () {
      const { data } = await detail(this.subject)
      this.list = data
      console.log(this.list)
    },
    // 题型
    translateQuestionType (num) {
      const questionTypeNum = questionType.reduce((pre, item) => { return { ...pre, [item.value]: item.label } }, {})
      return questionTypeNum[num]
    },
    // 难度
    translateDifficulty (num) {
      const difficultyNum = difficulty.reduce((pre, item) => { return { ...pre, [item.value]: item.label } }, {})
      return difficultyNum[num]
    }
  }
}
</script>

<style scoped>
 .el-col{
     padding: 5px 0;
 }
 .el-row{
     padding: 5px 0;
 }
 .question {
     color: blue;
 }

</style>
